<?php

class IndexController extends Zend_Controller_Action {

    public function init() {
        /* Initialize action controller here */
    }

    public function indexAction() {
         
         $this->view->showHomeBanner = TRUE;
		 $this->view->showMetaDescription = TRUE;
		 $this->view->showMetaKeyword = TRUE;
		 $this->view->headTitle('Citrusbug - Web Development, Web Design, Mobile Application Development');
		 $this->view->META_DESCRIPTION = "Citrusbug is now recognized through out the world as a cutting edge web development, Mobile Application Development and Graphic Design company. ";
		 $this->view->META_KEYWORDS = "web development, web design, mobile application development, seo, graphic design, offshore software development, PHP , linux programming, application development, usa, uk, canada, germany ,netherland , denmark";
    }
	
    public function callbackAction() {
	
	global $config;
	$pubKey = $config->CAPTCHA_PUBLIC_KEY;
	$privKey = $config->CAPTCHA_PRIVATE_KEY;

	$recaptcha = new Zend_Service_ReCaptcha($pubKey, $privKey);
	$this->view->recaptcha = $recaptcha;
	
	$callBackForm = new Form_CallbackForm();
	
	$succesMeessage = "";
	$errorMessage = Array();

	if ($this->getRequest()->isPost()) {

	    if ($callBackForm->isValid($_POST)) {

		try {
		    $result = $recaptcha->verify(
				    $_POST['recaptcha_challenge_field'],
				    $_POST['recaptcha_response_field']
		    );
		    if (!$result->isValid()) {
			$callBackForm->addErrorMessage("Please Enter correct Captcha.");
			$errorMessage['0'] = $callBackForm->getErrorMessages();
		    } else {

			$callBackModel = new Model_Callback();
			// if the form is valid then create the new bug
			$result = $callBackModel->createCallBack(
					$callBackForm->getValue('name'),
					$callBackForm->getValue('company'),
					$callBackForm->getValue('email'),
					$callBackForm->getValue('phone')
			);

			$body = "";
			$body .= "Name : " . $callBackForm->getValue('name') . "<br/>";
			$body .= "Company : " . $callBackForm->getValue('company') . "\r<br/>";
			$body .= "Email : " . $callBackForm->getValue('email') . "\r<br/>";
			$body .= "Phone : " . $callBackForm->getValue('phone') . "\r<br/>";

			$mail = new Zend_Mail();
			$mail->setBodyText($body);
			$mail->setBodyHtml($body, "iso-8859-1");

			$mail->addTo('ketan.jems@gmail.com', 'Ketan Patel');
			$mail->addTo('vyasishanatc194@gmail.com', 'Vyas Ishan');
			$mail->addTo('info@citrusbug.com.com', 'Info Citrus Bug');
			$mail->setFrom('info@citrusbug.com', 'Info Citrus Bug');
			$mailSubject = "Call Back form Inquiry to ZFCMS by [". $callBackForm->getValue('name')."]";
			$mail->setReplyTo('info@citrusbug.com', 'Citrus Bug');
			$mail->addHeader('MIME-Version', '1.0');
			$mail->addHeader('Content-Transfer-Encoding', '8bit');
			$mail->addHeader('X-Mailer:', 'PHP/'.phpversion());
			$mail->setSubject($mailSubject);
			$mail->send();

			if ($result > 1) {
			    $callBackForm->reset();
			    $succesMeessage = "Thanks for contacting us! Will be in touch soon.";
			}
		    }
		} catch (Exception $e) {
		    $callBackForm->addErrorMessage("Please Enter Captcha.");
		    $errorMessage['0'] = $callBackForm->getErrorMessages();
		}
	    } else {
		$errorMessage = $callBackForm->getMessages();
	    }
	}
	
	$layout = $this->_helper->layout();
	$layout->setLayout('popup_layout');
	$this->view->headTitle('Citrus Bug');
	$this->view->form = $callBackForm;
	$this->view->errorMessage = $errorMessage;
	$this->view->succesMeessage = $succesMeessage;
    }

}

?>
